package com.haixiaoke.business;

import com.haixiaoke.common.annotation.Log;
import com.haixiaoke.common.core.domain.AjaxResult;
import com.haixiaoke.common.core.page.TableDataInfo;
import com.haixiaoke.common.enums.BusinessType;
import com.haixiaoke.common.utils.poi.ExcelUtil;
import com.haixiaoke.domain.LockUnlockLog;
import com.haixiaoke.service.ILockUnlockLogService;
import com.haixiaoke.system.controller.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 智能锁开锁记录Controller
 *
 * @author qixi
 * @date 2023-05-29
 */
@RestController
@RequestMapping("/business/unlockLog")
public class LockUnlockLogController extends BaseController {
    @Autowired
    private ILockUnlockLogService lockUnlockLogService;

    /**
     * 查询智能锁开锁记录列表
     */
    @PreAuthorize("@ss.hasPermi('business:unlockLog:list')")
    @GetMapping("/list")
    public TableDataInfo list(LockUnlockLog lockUnlockLog) {
        startPage();
        List<LockUnlockLog> list = lockUnlockLogService.selectLockUnlockLogList(lockUnlockLog);
        return getDataTable(list);
    }

    /**
     * 导出智能锁开锁记录列表
     */
    @PreAuthorize("@ss.hasPermi('business:unlockLog:export')")
    @Log(title = "智能锁开锁记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LockUnlockLog lockUnlockLog) {
        List<LockUnlockLog> list = lockUnlockLogService.selectLockUnlockLogList(lockUnlockLog);
        ExcelUtil<LockUnlockLog> util = new ExcelUtil<LockUnlockLog>(LockUnlockLog.class);
        util.exportExcel(response, list, "智能锁开锁记录数据");
    }

    /**
     * 获取智能锁开锁记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:unlockLog:query')")
    @GetMapping(value = "/{unlockId}")
    public AjaxResult getInfo(@PathVariable("unlockId") Long unlockId) {
        return success(lockUnlockLogService.selectLockUnlockLogByUnlockId(unlockId));
    }

    /**
     * 新增智能锁开锁记录
     */
    @PreAuthorize("@ss.hasPermi('business:unlockLog:add')")
    @Log(title = "智能锁开锁记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LockUnlockLog lockUnlockLog) {
        return toAjax(lockUnlockLogService.insertLockUnlockLog(lockUnlockLog));
    }

    /**
     * 修改智能锁开锁记录
     */
    @PreAuthorize("@ss.hasPermi('business:unlockLog:edit')")
    @Log(title = "智能锁开锁记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LockUnlockLog lockUnlockLog) {
        return toAjax(lockUnlockLogService.updateLockUnlockLog(lockUnlockLog));
    }

    /**
     * 删除智能锁开锁记录
     */
    @PreAuthorize("@ss.hasPermi('business:unlockLog:remove')")
    @Log(title = "智能锁开锁记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{unlockIds}")
    public AjaxResult remove(@PathVariable Long[] unlockIds) {
        return toAjax(lockUnlockLogService.deleteLockUnlockLogByUnlockIds(unlockIds));
    }
}
